package com.lotter.api.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.lotter.api.service.LotteryOrderService;
import com.lotter.common.exception.LotterCusException;
import com.lotter.context.CaipiaoKongContent;

/**
 * 定时从彩票站中取数据
 * 
 * @author zhangzechi
 *
 */
@Component
public class CaipiaoKongTask {

	// 记录日志
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private LotteryOrderService lotteryOrderService;

	// 获取当天可投数据
	//
	@Scheduled(cron = "0 0/10 1-23 * * ?")
	public void getDateToday() {
		try {
			System.out.println("开始执行  今天数据");
			CaipiaoKongContent.assembling_TODAY();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("今天 彩票站获取数据有误,请检查代码");
		}
	}

	// 获取明天可投数据
	// 执行周期：每天凌晨00:08,00:48执行一次
	@Scheduled(cron = "0 0/11 1-23 * * ?")
	public void getDateTOMORROW() {
		try {
			System.out.println("开始执行  明天数据");
			CaipiaoKongContent.assembling_TOMORROW();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("明天 彩票站获取数据有误,请检查代码");
		}
	}
	
	// 获取后天可投数据
	// 执行周期：每天凌晨00:08,00:48执行一次
	@Scheduled(cron = "0 0/12 1-23 * * ?")
	public void getDateTOTHIRD() {
		try {
			System.out.println("开始执行  后天数据");
			CaipiaoKongContent.assembling_THIRD();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("后天 站获取数据有误,请检查代码");
		}
	}

	// 将比赛结束录入数据库
	@Scheduled(cron = "0 0/30 1-23 * * ?")
	public void getDateYesterday() {
		try {
			System.out.println("开始执行 录入数据");
			lotteryOrderService.LotteryWinning();
		} catch (LotterCusException e) {
			e.printStackTrace();
			logger.error("彩票站开奖业务有误");
		}
	}
	
	//开奖
	@Scheduled(cron = "0 0/30 1-23 * * ?")
	public void lottery_open(){
		try {
			System.out.println("开始执行 执行开奖");
			lotteryOrderService.LotteryOpen();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("彩票站开奖业务有误");
		}
	}

	
}
